import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/pages/login/login_page.dart';
import 'package:flutter_enjoy_plus/pages/profile/profile_page.dart';
import 'package:flutter_enjoy_plus/pages/tabbar_page.dart';
import 'package:flutter_enjoy_plus/utils/TokenManager.dart';

import 'notice/notice_detail.dart';

void main() {
  runApp(MaterialApp(
    routes: {
      '/': (context) => const TabbarPage(),
      '/notice_detail': (context) => const NoticeDetail(),
      "/login": (context) => const LoginPage(),
      // "/profile": (context) => const ProfilePage()
    },
    onGenerateRoute: (RouteSettings settings) {
      print(settings.name); // 跳转去的路由名
      var token = tokenManager.getToken();
      if (token != '') {
        // 有token
        if (settings.name == '/profile') {
          return MaterialPageRoute(
            builder: (context) => ProfilePage(),
          );
        } else {
          return null;
        }
      } else {
        // 没有token
        return MaterialPageRoute(
          builder: (context) => LoginPage(),
        );
      }
    },
  ));
}
